#ifndef ENCRYPTEDVALUE_H
#define ENCRYPTEDVALUE_H

#define VALUE_ENCRYPT_KEY 58598512

#include "Macro.h"

TSP_NS_START

class EncryptedValue
{
public:
    EncryptedValue(){m_value = 0;}
    ~EncryptedValue(){}

    template<typename T>
    void setValue(const T& value)
    {
        long long temp = 0;
        memcpy(&temp, &value, sizeof(value));
        m_value = temp ^ VALUE_ENCRYPT_KEY;
        m_value *= 1 - (m_value % 2 == 1)*2;
        return;
    }

    template<typename T>
    void getValue(T& value)
    {
        value = 0;
        m_value *= 1 - (m_value % 2 == 1)*2;
        long long encrypted = m_value ^ VALUE_ENCRYPT_KEY;
        memcpy(&value, &encrypted, sizeof(value));
        return;
    }

    template<typename T>
    void getValue(T* value)
    {
        *value = 0;
        m_value *= 1 - (m_value % 2 == 1)*2;
        long long encrypted = m_value ^ VALUE_ENCRYPT_KEY;
        memcpy(value, &encrypted, sizeof(*value));
        return;
    }

protected:
    long long m_value;

private:
    TSP_DISALLOW_COPY_AND_ASSIGN(EncryptedValue);
};

TSP_NS_END

#endif //ENCRYPTEDVALUE_H
